package com.personalblog.controller;

import com.personalblog.handler.ApiNotFindUserException;
import com.personalblog.mapper.BlogMapper;
import com.personalblog.utils.RedisUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import java.util.Arrays;

/**
 * @author jxau_scf
 * @date 2021/3/16 - 20:32
 */
@Controller
public class TestController {
    @RequestMapping("/test")
    public String test(ModelMap map){
        map.put("thText", "设置文本内容");
        map.put("thUText", "设置文本内容");
        map.put("thValue", "设置当前元素的value值");
        map.put("thEach", Arrays.asList("列表", "遍历列表"));
        map.put("thIf", "msg is not null");
        //map.put("thObject", new UserEntity("sadfa","asfasfd","asfsaf","asdfasf","saf","asfd","sadf",1));
//        if (true){
//            throw new ApiNotFindUserException("该用户找不到");
//        }

        return "test";
    }

    @Resource
    private RedisUtil redisUtil;

    @Autowired
    private BlogMapper blogMapper;

    @RequestMapping("/testRedis")
    @ResponseBody
    public String testRedis(){
//        if (!redisUtil.hasKey("test:01")){
//            redisUtil.set("test:01","测试redis缓存");
//        }
//        System.out.println(redisUtil.get("test:01"));
        if (!redisUtil.hasKey("blogs")){
            redisUtil.set("blogs",blogMapper.findBlogs());
        }
        System.out.println(redisUtil.get("blogs"));
        return "success";
    }

//    @RequestMapping("/")
//    public String index(){
//        return "index";
//    }
//    @RequestMapping("/admin")
//    public String admin(){
//        return "admin/login";
//    }
//
//    @RequestMapping("/admin/index")
//    public String adminIndex(){
//        return "admin/index";
//    }
//    @RequestMapping("/ajax")
//    @ResponseBody
//    public String ajaxTest(String url){
//        System.out.println(url);
//        return "nice";
//    }

}
